package xFGE.xDisplay.xUI
{
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;

	import xFGE.Interface.IPanel;
	import xFGE.manager.PanelManager;
	import xFGE.util.Gradual;
	import xFGE.xDisplay.xScene.*;
	
	public class PanelBase implements IPanel
	{
		/**
		 * Panel 控制的mc 
		 */
		private var _mc:DisplayObject;
		
		/**
		 * Panel所在层的名字 
		 */
		protected var _layerObj:xLayerObj;
		
		/**
		 * 是否已经初始化 
		 */
		protected var _hasInit:Boolean = false;
		
		/**
		 * 面板名字 
		 */
		protected var _panelName:String;
		
		/**
		 * 构造函数 
		 * @param layerName
		 * 
		 */
		public function PanelBase(layer:xLayerObj,panelMC:DisplayObject,name:String)
		{
			_layerObj = layer;
			_mc = panelMC;
			if(name!=null)
				panelMC.name = name;
			_panelName= name;
			_mc.addEventListener(MouseEvent.MOUSE_UP,_onPanelTop);
			_mc.addEventListener(MouseEvent.MOUSE_DOWN,_onPanelTop);
			PanelManager.GetInstance().AddPanel(this,name);
		}
		
		/**
		 * panel初始化
		 * @return 
		 * 
		 */
		protected function init():Boolean
		{
			_hasInit = true;
			return true;
		}
		/**
		 * panel打开
		 * @param value
		 * 
		 */
		public function panelIn(value:*=null):void
		{
			if(!_hasInit) init();
			if(_layerObj.contains(_mc))return;
			_mc.visible = false;
			_layerObj.addChild(_mc);
			Gradual.gradualShow(_mc);
		}
		/**
		 * panel关闭
		 * @param value
		 * 
		 */
		public function panelOut(value:*=null):void
		{
			if(!_layerObj.contains(_mc)) return;
			_layerObj.removeChild(_mc);
		}
		/**
		 * 
		 * 
		 */
		public function panelOver():void
		{
			
		}
		/**
		 *  显示/隐藏
		 * @param flag
		 * 
		 */
		public function setVisabled(flag:Boolean):void
		{
			_mc.visible = flag;
		}
		
		private function _onPanelTop(eve:MouseEvent):void
		{
			layer.SetTopMost(_mc);
		}
		/**
		 * 获取显示对象 
		 * @return 
		 * 
		 */
		public function getDisplayObject():DisplayObject
		{
			return _mc;
		}
		
		public function get panelName():String
		{
			return _panelName;
		}
		public function get layer():xLayerObj
		{
			return _layerObj;
		}

	}
}